﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SanctusSoftware.Music.Chords;

namespace SanctusSoftware.Music.ChordSheetEditor.Client
{
  public static class SentenceTransposer
  {


    // Percent as an Integer
    public static bool IsChordLine(ISentence sentence, int minimumChordMatchPercent)
    {
      decimal dec = Convert.ToDecimal(minimumChordMatchPercent) / 100m;
      return IsChordLine(sentence, dec);
    }

    // Percent in its true decimal form
    public static bool IsChordLine(ISentence sentence, decimal minimumChordMatchPercent)
    {
      return (GetIsChordSentencePercent(sentence) >= minimumChordMatchPercent);
    }

    public static decimal GetIsChordSentencePercent(ISentence sentence)
    {
      var results = sentence.GetWordsAndPunctuation().Select(word => ChordTransposer.GetChordMatchPercent(word.Text, word.IsSpelledCorrectly));
      if (results.ToArray().Length == 0)
      {
        return 0;
      }
      else
      {
        decimal avg = results.Average();
        return avg;
      }
    }



  }
}
